package hz.mobileproject.pda.ui.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;


import java.util.ArrayList;
import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.ui.adapter.DialogListAdapter;

/**
 * Created by Lc on 2017/9/16.
 */

public class CustomListDialog extends BaseCustomDialog implements AdapterView.OnItemClickListener {

    private List<String> strList;

    private ListView listView;

    private OnListDialogClick oldc;


    public CustomListDialog(Context context, String[] datas) {
        super(context);
        strList = new ArrayList<String>();
        for(String data : datas){
           strList.add(data);
        }
    }
    public CustomListDialog(Context context, ArrayList<String> list) {
        super(context);
        strList = new ArrayList<String>();
        for(String str : list){
            strList.add(str);
        }
    }

    @Override
    protected int bindView() {
        return R.layout.dialog_costom_list;
    }

    @Override
    protected void initData() {
        listView = (ListView) findViewById(R.id.lv_dialog);
        listView.setAdapter(new DialogListAdapter(mContext,strList));
        listView.setOnItemClickListener(this);
    }


    public void setOnListDialogClick(OnListDialogClick sgocl) {
        this.oldc = sgocl;
    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        dismiss();
        if(oldc != null){
            oldc.onClick(position,strList.get(position));
        }
    }

    public interface OnListDialogClick{
        void onClick(int position, String str);
    }
}
